package praktikum_2_ylesanded.testid;

import junit.framework.TestCase;
import praktikum_2_ylesanded.ylesanne_1.PriorityQueue;

import java.util.Arrays;

/**
 * Created by IntelliJ IDEA.
 * User: Jaan Sepp ja Martti Elias
 * Date: 20.10.11
 * Time: 15:37
 */
public class PriorityQueueTest extends TestCase {

  PriorityQueue priorityQueue = new PriorityQueue();

  public void testEnqueue() throws Exception {
    assertEquals(true, priorityQueue.isEmpty());

    priorityQueue.enqueue(18);
    assertEquals(false, priorityQueue.isEmpty());
    assertEquals(Arrays.toString(new int[]{0, 18, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));


    priorityQueue.enqueue(32);
    assertEquals(Arrays.toString(new int[]{0, 18, 32, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    priorityQueue.enqueue(2);
    assertEquals(Arrays.toString(new int[]{0, 2, 32, 18, 0, 0, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    priorityQueue.enqueue(5);
    assertEquals(Arrays.toString(new int[]{0, 2, 5, 18, 32, 0, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    priorityQueue.enqueue(1);
    assertEquals(Arrays.toString(new int[]{0, 1, 2, 18, 32, 5, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    priorityQueue.enqueue(17);
    assertEquals(Arrays.toString(new int[]{0, 1, 2, 17, 32, 5, 18, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
  }

  public void testDequeue(){
    priorityQueue.enqueue(18);
    priorityQueue.enqueue(32);
    priorityQueue.enqueue(2);
    priorityQueue.enqueue(5);
    priorityQueue.enqueue(1);
    priorityQueue.enqueue(17);
    assertEquals(Arrays.toString(new int[]{0, 1, 2, 17, 32, 5, 18, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(1, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0, 2, 5, 17, 32, 18, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(2, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0, 5, 18, 17, 32, 0, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(5, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0, 17, 18, 32, 0, 0, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(17, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0, 18, 32, 0, 0, 0, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(18, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0, 32, 0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(32, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0, 0}), Arrays.toString(priorityQueue.getDynamicArray()));
    assertEquals(0, priorityQueue.dequeue());
    assertEquals(Arrays.toString(new int[]{0}), Arrays.toString(priorityQueue.getDynamicArray()));

  }

}
